package com.easylinkin.linkappapi.facerecognition.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easylinkin.linkappapi.facerecognition.entity.FacePhoto;
import com.easylinkin.linkappapi.facerecognition.mapper.FacePhotoMapper;
import com.easylinkin.linkappapi.facerecognition.service.FacePhotoService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FacePhotoServiceImpl extends ServiceImpl<FacePhotoMapper, FacePhoto> implements FacePhotoService {

    @Override
    public FacePhoto queryPhotoWithId(String photoId) {
        QueryWrapper<FacePhoto> qw = new QueryWrapper<>();
        qw.eq("photo_id", photoId);

        List<FacePhoto> facePhotos = baseMapper.selectList(qw);
        if (facePhotos.isEmpty()) {
            return null;
        }
        return facePhotos.get(0);
    }

    @Override
    public FacePhoto queryPhotoWithUrl(String photoUrl) {
        QueryWrapper<FacePhoto> qw = new QueryWrapper<>();
        qw.eq("photo_url", photoUrl);

        return baseMapper.selectOne(qw);
    }
}
